<?php
use yii\helpers\Url;
$this->title = '中国人事网';
?>
<div class="appr_sidebar m_left_menu">
    <?=$this->render("@app/views/public/_leftMenu") ?>
</div>
<div class="appr_bd_wrap">
    <div class="judge_wrap">
        <div class="judge_wrap judge_size_b evaluate_detail">
            <div class="appr_bread">
                <em>员工信息(Hr)</em>
            </div>
            <div class="judge_content">
                <div id="grid-list"></div>
            </div>
        </div>
    </div>
</div>
<script>
var _grid = $("#grid-list"),dataSource,editWindow=$("<div id='grid-add'></div>"),alignCenterAttribute = { style: "text-align: center" };
;
$(document).ready(function () {
   
    dataSource = new kendo.data.DataSource({
        transport: {
            read:  {
                url: "<?=Url::to(['list']); ?>",
                dataType: "json"
            },
            parameterMap: function(options, operation) {
                if (operation !== "read" && options.models) {
                    return {models: kendo.stringify(options.models)};
                }
            }
        },
        batch: true,
        pageSize: 18,
        schema: {
            model: {
                id: "id",
                fields: {
                    id: { field:"id" ,editable: false, nullable: true },
                    name_cn_long: { field:"name_cn_long",type: "string"},
                    name_en_long: { field:"name_en_long",type: "string"},
                    department_name: { field:"department_name" ,type: "string"},
                    position_name: { field:"position_name", type: "string" },
                    group_name :{field:"group_name" ,type:"string"},
                    hired_date :{field:"hired_date" ,type: "date"},
                    position_status : { field:"position_status" ,type:"string" },
                    finger_print_number :{ field:"finger_print_number" ,type:"string"}
                }
            },
            data:function(d){
                return d.list;

            },
            total:function(d){
        
                return d.count
            }
        }
    });

    _grid.kendoGrid({
        dataSource: dataSource,
        pageable: true,
        sortable: true,
        reorderable: true,
        groupable: true,
        resizable: true,
        filterable: true,
        columnMenu: true,
        editable: "popup",
        columns: [
         
            { 
                field:"name_cn_long", 
                title: "中文名" ,
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },
            { 
                field: "name_en_long", 
                title:"英文名" ,
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },
            { 
                field: "department_name", 
                title:"部门",
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },
            { 
                field: "group_name", 
                title:"组别",
                hidden:true ,
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },
            { 
                field: "position_name", 
                title:"职位" ,
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },
            { 
                field: "finger_print_number",
                title:"指纹号" ,
                hidden:true,
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },

            { 
                field: "hired_date",
                title:"入职日期" ,
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute,
                type: "date",
                format: "{0:dd/MM/yyyy}"
            },

            { 
                field: "position_status",
                title:"岗位状态" ,
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },

            { 
                command: [
                    {
                        text:"编辑",
                        imageClass:"k-icon k-edit",
                        click:onEdit
                    }
                ], 
                title: "", 
                width: "150px",
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            }
        ]
    });
});

function onEdit(e){
    var tr = $(e.target).closest("tr");
    var data = this.dataItem(tr);
    if (!editWindow.data("kendoWindow")) {
        editWindow.kendoWindow({
            width: "800px",
            height:"800px",
            title: "编辑",
            actions: [
                "Close"
            ],
            position:{
                left:"30%",
                top:"20%"
            }

        }).data("kendoWindow");
    }
    editWindow.data("kendoWindow").refresh({
        url: "<?=Url::to(['edit']) ?>",
        data: { id: data.id }
    });

    editWindow.data("kendoWindow").open();
}

</script> 

